package com.briup.jz.web.controller;

import com.briup.jz.bean.Article;
import com.briup.jz.bean.BaseUser;
import com.briup.jz.service.IArticleService;
import com.briup.jz.service.IBaseUserService;
import com.briup.jz.utils.CustomerException;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Api(description="用户信息相关接口")
@RequestMapping("/baseUser")
public class BaseUserController {
    @Autowired
    private IBaseUserService baseUserService;

    @ApiOperation(value = "查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="username",value = "用户名",paramType = "query")
    })
    @GetMapping("query")
    public Message query(String username,String status, Long roleId){
        List<BaseUser> list = baseUserService.query(username, status, roleId);
        return MessageUtil.success(list);
    }



    @ApiOperation(value = "删除指定id的用户信息")
    @GetMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
        baseUserService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "编号", paramType = "form"),
            @ApiImplicitParam(name = "username", value = "用户名", paramType = "form"),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "form"),
            @ApiImplicitParam(name = "telephone", value = "手机号", paramType = "form"),
            @ApiImplicitParam(name = "realname", value = "姓名", paramType = "form"),
            @ApiImplicitParam(name = "gender", value = "性别", paramType = "form"),
            @ApiImplicitParam(name = "birth", value = "生日", paramType = "form"),
            @ApiImplicitParam(name = "email", value = "email", paramType = "form"),
            @ApiImplicitParam(name = "status", value = "状态", paramType = "form"),
            @ApiImplicitParam(name = "user_face", value = "用户头像", paramType = "form"),
            @ApiImplicitParam(name = "register_time", value = "注册时间", paramType = "form"),
            @ApiImplicitParam(name = "nation", value = "民族", paramType = "form"),
            @ApiImplicitParam(name = "id_card", value = "身份证号", paramType = "form"),
            @ApiImplicitParam(name = "idcard_photo_positive", value = "身份证正面", paramType = "form"),
            @ApiImplicitParam(name = "idcard_photo_negative", value = "身份证反面", paramType = "form"),
            @ApiImplicitParam(name = "bank_card", value = "银行卡号", paramType = "form"),
            @ApiImplicitParam(name = "bank_card_photo", value = "银行卡照片", paramType = "form"),
            @ApiImplicitParam(name = "balance", value = "账户余额", paramType = "form"),
            @ApiImplicitParam(name = "certification_status", value = "实名制状态", paramType = "form"),
            @ApiImplicitParam(name = "certification_time", value = "实名制时间", paramType = "form"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BaseUser baseUser) {
        baseUserService.saveOrUpdate(baseUser);
        return MessageUtil.success("更新成功");
    }
}
